package domain;

import java_persistence.UserMapper;

/**
 * @author joseph simoneau <simoneau@gatech.edu>
 *
 */
public class User {

	private String username;
	private String password;
	private String name;
	private String phone_number;
	private String address;
	private String email;
	private boolean active_account;

	public User() {
		super(); 

		this.username = null;
		this.password = null;
		this.name = null; 
		this.phone_number = null;
		this.address = null;
		this.email = null;
		this.active_account = true; 
	}
	
	public User( String un, String pw, String n, String pn, String ad, String em, Boolean aa) {
		super();
		
		this.username = un;
		this.password = pw;
		this.name = n;
		this.phone_number = pn;
		this.address = ad;
		this.email = em;
		this.active_account = aa;
	}
	
	public String getUsername() {
		return username;
	}
	public String getPassword() {
		return password;
	}
	public String getName() {
		return name;
	}
	public String getPhone_number() {
		return phone_number;
	}
	public String getAddress() {
		return address;
	}
	public String getEmail() {
		return email;
	}
	public Boolean getActive_account() {
		return active_account;
	}
	
	
	public void setUsername(String username) {
		this.username = username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setPhone_number(String phone_number) {
		this.phone_number = phone_number;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public void setActive_account(boolean active_account) {
		this.active_account = active_account;
	}
	
	
	// CREATES
	
	/**Saves 'this''s information in the database.  
	 * @param umap retrieved from a valid, open SqlSession object.
	 */
	public void create(UserMapper umap) {
		if( username != null ) {
			umap.create( this.username, this.password, this.name, this.phone_number, this.address, this.email, this.active_account );
			//umap.create2(this);
		}
	}
	
	// RETREVES
	
	// UPDATES
	
	/**Updates 'this''s entry in the database to reflect its current state.  Please note that it is not possible to change a username using this method.
	 * @param umap retrieved from a valid, open SqlSession object.
	 */
	public void update(UserMapper umap) {
		if( username != null ) {
			umap.update( this.username, this.password, this.name, this.phone_number, this.address, this.email, this.active_account );
		}
	}
	
	// DELETES
	
	/**Deletes 'this's entry from the database.  Please note that users must not be a special class of user within the database or this method will cause an error.
	 * @param umap retrieved from a valid, open SqlSession object.
	 */
	public void delete(UserMapper umap) {
		umap.delete( this.username );
	}
	
	
}
